package com.example.riseofthedefender;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.content.Context;

public class LoadTextFile {
	public static void load(final Context context, final int resourceId)
	{
		final InputStream inputStream = context.getResources().openRawResource(
				resourceId);
		final InputStreamReader inputStreamReader = new InputStreamReader(
				inputStream);
		final BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
		
		try
		{
			int c;
			c = bufferedReader.read();
			int row = 0;
			int col = 0;
			float size = 64;
			while (c != -1)
			{
				switch (c) {
				case '0':
					new Soul(col*size,row*size+size,col*size+size,row*size);
					break;
				case '1':
					new Ground(col*size,row*size+size,col*size+size,row*size);
					break;
				case 'S':
					new Soul(col*size,row*size+size,col*size+size,row*size);
					break;
				default:
					break;
				}

	        	if(c=='\n')
	        	{
	        		Camera.boundE = (int) (col * size);
	        		col=0;
	        		++row;
	        		Camera.boundN = (int) (row * size);
	        	}
	        	else
	        		++col;
	        	c = bufferedReader.read();
			}
		}
		catch (IOException e){}
	}
}
